package com.marvels.financial.collection.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.marvels.common.dto.MarvelsResultDTO;
import com.marvels.common.exception.MarvelsBusinessException;
import com.marvels.common.exception.MarvelsErrorCode;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.financial.collection.api.LoanAccountApi;
import com.marvels.financial.collection.dto.CollectAccountDTO;
import com.marvels.financial.collection.dto.CommonConditionDTO;
import com.marvels.financial.loan.dto.McfeCustomerRepaymentPlanDTO;

/**
 * 还款信息对外接口
 * @author zhaosa
 *
 */
@RestController
@RequestMapping("/financial/repayment/api")
public class RepaymentInfoApiController {
	@Autowired
	private LoanAccountApi loanAccountApi;
	
	/**
	 * 查询还款计划列表
	 * @param dto
	 * @return
	 * @throws MarvelsBusinessException
	 */
	@RequestMapping("/planList")
	@ResponseBody
	public PageInfo<McfeCustomerRepaymentPlanDTO>  planList(@RequestBody CommonConditionDTO dto) throws MarvelsBusinessException{
		return loanAccountApi.planList(dto);
	}
	/**
	 *查询贷款合同信息
	 * @param loanId
	 * @return
	 * @throws MarvelsBusinessException
	 */
	@RequestMapping("/selectAccountInfo")
	@ResponseBody
	public CollectAccountDTO selectAccountInfo(@RequestBody String loanId) throws MarvelsBusinessException{
		return loanAccountApi.selectAccountInfo(loanId);
	}

	/**
	 * 查询逾期信息
	 * @param loanId
	 * @return
	 * @throws MarvelsBusinessException
	 */
	@RequestMapping("/selectAccountOverdueInfo")
	@ResponseBody
	public Map<String, String> selectAccountOverdueInfo(@RequestBody List<String> loanId) throws MarvelsBusinessException{
		return loanAccountApi.selectAccountOverdueInfo(loanId);
	}
	
	/**
	 *查询还款计划信息
	 * @param loanId
	 * @return
	 * @throws MarvelsBusinessException
	 */
	@RequestMapping("/queryPayPlanInfo")
	@ResponseBody
	public MarvelsResultDTO queryPayPlanInfo(@RequestBody(required=false) CommonConditionDTO dto) throws MarvelsBusinessException{
		try {
			return loanAccountApi.queryPayPlanInfo(dto);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>查询还款计划信息FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), null);
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>查询还款计划信息", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), "查询还款计划信息", null);
		}
	}

}
